package Java复习;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;

class Text extends JFrame{
    public Text() throws HeadlessException {
        text();
        scree();
        this.setVisible(true);
    }
    public void scree(){
        this.setTitle("文本");
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
        this.pack();
    }
    public void text(){
        TextField field = new TextField();
//        field.setFont(new Font("宋体", 1, 25));
        JTextArea area = new JTextArea(5,30);
        area.setLineWrap(true);
        field.addTextListener(new TextListener() {
            @Override
            public void textValueChanged(TextEvent e) {
                area.setText(field.getText());
            }
        });
        field.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {
                if (e.getKeyCode()==0){
                    area.setText("");
                }
            }

            @Override
            public void keyPressed(KeyEvent e) {

            }

            @Override
            public void keyReleased(KeyEvent e) {

            }
        });
        this.add(field, BorderLayout.NORTH);
        this.add(area);
    }
}
public class 图形Num2 {
    public static void main(String[] args) {
        Text t = new Text();
    }
}
